﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Meqs.Entity;
using Meqs.Logic.Interface;
using System.Collections.Generic;
using Meqs.Logic;

public partial class Custom_ucExamClass : System.Web.UI.UserControl
{
    private List<ClsInfo> listClsInfo = new List<ClsInfo>();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetClsInfo();
            GetClasses();
        }
    }
    protected int currIn = 0;
    protected string GetOption(int rid, string ClsName)
    {

        string str = "<option value=" + rid + " " + ((currIn == 0) ? "" : "selected='selected'") + ">" + ClsName + "</option>";
        currIn = rid;
        return str;
    }

    private void GetClasses()
    {
        string s = "";
        int examId = 0, examType = 0;

        examId = SchoolCookie.ExamID;
        examType = SchoolCookie.ExamType;

        if (examId > 0)
        {
            if (examType == 0)//校级
            {

                repeatReport.DataSource = GetSchoolExamClass(examId);
                repeatReport.DataBind();
            }
            else
            {
                repeatReport.DataSource = GetEduExamClass(examId);
                repeatReport.DataBind();
            }
        }
    }

    private void GetClsInfo()
    {
        IClsInfoLogic logic = Container<IClsInfoLogic>.Instance;
        Hashtable table = new Hashtable();
        table.Add("SchoolMark", CommonScore.GetSchoolMark);
        listClsInfo = (List<ClsInfo>)logic.FindAll(table);
    }


    /// <summary>
    /// 获取局级的考试班级
    /// </summary>
    /// <param name="examId"></param>
    /// <returns></returns>
    private List<ClsInfo> GetEduExamClass(int examId)
    {
        List<ClsInfo> listTable = new List<ClsInfo>();

        IExamClassEducationLogic logic = Container<IExamClassEducationLogic>.Instance;
        Hashtable table = new Hashtable();
        table.Add("ExamID", examId);
        List<ExamClassEducation> list = (List<ExamClassEducation>)logic.FindAll(table);

        foreach (ExamClassEducation item in list)
        {
            foreach (ClsInfo clsInfo in listClsInfo)
            {
                Hashtable table2 = new Hashtable();
                if (item.ClassID == clsInfo.RID)
                {
                    listTable.Add(clsInfo);
                }
            }
        }
        ListSort<ClsInfo> sort = new ListSort<ClsInfo>(listTable, "ClsNo", true);
        return (List<ClsInfo>)sort.Sort();
    }

    private List<ClsInfo> GetSchoolExamClass(int examId)
    {
        List<ClsInfo> listTable = new List<ClsInfo>();

        IExamClassSchoolLogic logic = Container<IExamClassSchoolLogic>.Instance;
        Hashtable table = new Hashtable();
        table.Add("ExamID", examId);
        table.Add("SchoolMark", CommonScore.GetSchoolMark);
        List<ExamClassSchool> list = (List<ExamClassSchool>)logic.FindAll(table);

        foreach (ExamClassSchool item in list)
        {
            foreach (ClsInfo clsInfo in listClsInfo)
            {
                Hashtable table2 = new Hashtable();
                if (item.SchoolClassID == clsInfo.RID)
                {
                    listTable.Add(clsInfo);
                }
            }
        }
        ListSort<ClsInfo> sort = new ListSort<ClsInfo>(listTable, "ClsNo", true);
        return (List<ClsInfo>)sort.Sort();
    }
}
